 ///
 /// @file    virtual_multi_inherit.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-15 14:39:40
 ///
 
#include <stdio.h>
#include <iostream>

using std::cout;
using std::endl;


class A 
{
public:
	virtual void a()
	{	cout << "A::a()" << endl;	}

	virtual void b()
	{	cout << "A::b()" << endl;}

	virtual void c()
	{	cout << "A::c()" << endl;	}
};


class B
{
public:
	virtual void a()
	{	cout << "B::a()" << endl;	}

	virtual void b()
	{	cout << "B::b()" << endl;	}

	void c()
	{	cout << "B::c()" << endl;	}

	void d()
	{	cout << "B::d()" << endl;	}
};

class C : public A, public B
{
public:
#if 1
	virtual void a()
	{	cout << "C::a()" << endl;	}	
#endif

	void c()
	{	cout << "C::c()" << endl;	}

	void d()
	{	cout << "C::d()" << endl;	}
};

int main(void)
{
	C c;
	cout << "c's size = " << sizeof(c) << endl;
	//c.b();//error 虚函数效果失效,二义性
	
	cout << endl;

	A * pa = &c;
	printf("pa = %p\n", pa);
	
	pa->a();//C::c()
	pa->b();//A::b()
	pa->c();//C::c()
	cout << endl;

	B * pb = &c;
	printf("pb = %p\n", pb);
	pb->a();//C::a()
	pb->b();//B::b()  虚函数
	pb->c();//B::c()  非虚函数
	pb->d();//B::d()  非虚函数
	cout << endl;

	C * pc = &c;
	printf("pc = %p\n", pc);
	pc->a();//表现虚函数
	//pc->b();//二义性
	pc->c();//并不表现虚函数特性
	pc->d();//隐藏


	return 0;
}
